#include "mymedia.h"
#include <QMediaPlayer>
#include <QMediaPlaylist>
MyMedia *MyMedia::mm = nullptr;

MyMedia::MyMedia(QObject *parent) : QObject(parent)
{
    //实例化对象
    player = new QMediaPlayer;
    playlist = new QMediaPlaylist;
    //添加歌曲到播放列表
    playlist->addMedia(QUrl("background_music1.mp3"));
    playlist->setCurrentIndex(0);
    //设置播放列表
    player->setPlaylist(playlist);
}

MyMedia *MyMedia::getObject()
{
    if(mm == nullptr)
        mm = new MyMedia;
    return mm;
}

void MyMedia::play()
{
    player->play();
}

void MyMedia::pause()
{
    player->pause();
}

void MyMedia::stop()
{
    player->stop();
}
